package product

import (
	"energy-amiot-platform/core"
	"energy-amiot-platform/repository"
	"energy-amiot-platform/utils/respout"
	"strconv"

	"github.com/gin-gonic/gin"
)

// @Tags 产品管理
// @Summary 添加一个产品
// @Description 添加一个产品
// @Product json
// @Param   companyId query string true		"企业标识"
// @Success 200 {object} response.Response{result=response.PageData{list=dbspo.Product}} "Ok"
// @Router /fui/product [get]
func pagingQueryForFui(ctx *gin.Context) {
	var handleCode = 5
	companyId, err := strconv.ParseUint(ctx.Query("companyId"), 10, 64)
	if err != nil {
		respout.SendError(ctx, core.APP.Code, moduleCode, handleCode, 0, respout.StrErrParse, err, nil)
		return
	}

	db := core.DATABASE.Cur()
	tx, infos := repository.PRODUCT.FindAllToBriefInfos(db, companyId)
	if err = tx.Error; err != nil {
		respout.SendError(ctx, core.APP.Code, moduleCode, handleCode, 1, respout.StrFail, err, nil)
		return
	}
	if len(infos) == 0 {
		respout.SendError(ctx, core.APP.Code, moduleCode, handleCode, 1, respout.StrFail, respout.ErrRecordNotFound, nil)
		return
	}

	respout.Ok(ctx, infos)
}
